package logic

import (
	"context"
	"shenzhou/B/srv/car"

	"shenzhou/B/api/internal/svc"
	"shenzhou/B/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsAddLogic) GoodsAdd(req *types.GoodsAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.CarSrvs.GoodsAdd(l.ctx, &car.GoodsAddRequest{
		GoodsTitle:  req.GoodsTitle,
		GoodsPrice:  float32(req.GoodsPrice),
		GoodsCover:  req.GoodsCover,
		GoodsStock:  req.GoodsStock,
		GoodsStatus: req.GoodsStatus,
		LikeCount:   req.LikeCount,
	})
	if err != nil {
		return &types.Response{
			Msg:  "商品发布失败",
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "商品发布成功",
		Code: 200,
		Data: add,
	}, nil
}
